/**
 *  The Yz.Form class
 */
(function(Yz) {
    if ( typeof(Yz) != "function" ) {
        throw "Failed to identify the root Yz object";
    }

    // prevent multiple execution
    if ('Form' in Yz) {
        return;
    }

    Yz.Form = function(name)
    {
        if (name in Yz.Form.forms)
            return Yz.Form.forms[name];
        this.name = name;
        this.HTMLFormElement = document.forms[name];
        Yz.Form.forms[name] = this;
    }


    /****************************
     *      Implementation      *
     ****************************/

    Yz.Form.forms = {}

    /**
     *  List of form's elements
     */
    Yz.Form.prototype = {
        elements: {},
        name: null,
        HTMLFormElement: null
    }

    /**
     *  Element class
     */
    Yz.Form.Element = function(form, elName)
    {
        console.log("new Element " + elName);
        if (elName in form.elements)
            return form.elements[elName];
        this.name = elName;
        this.form = form;
        form.elements[elName] = this;
        this.init();
    }
    Yz.Form.Element.prototype = {
        name: null,
        form: null,
        formElement: null,
        value: null,

        init: function() {
            console.log("init: creating Form.Element " + this.name);
        }
    }

})(window.Yz);
